package com.newbie.pet.wrap;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jdk.nashorn.internal.objects.annotations.Constructor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * 类描述：分页body体参数
 *
 * @author zhangkailiang
 * @date 2020/5/23
 */
@ApiModel("分页数据")
@Data
@Accessors(chain = true)
public class DPage<E> {

    @ApiModelProperty(value = "分页信息")
    private IPage page;

    @ApiModelProperty(value = "响应数据")
    private E info;

    public static <E> DPage<E> of(IPage iPage, Page page) {
        iPage.setTotalNum(page.getTotalElements());
        iPage.setTotalPage(page.getTotalPages());
        return new DPage().setPage(iPage).setInfo(page.toList());
    }
}
